Yacon.component.TSqlGrid = function(conText){
	
	Yacon.apply(this,conText);
	
	if(this.view){
		this.element = this.view;
		this.elementID = this.view.id;
		this.elementType = this.view.type;
	}
	
	this.spinner = new Yacon.widget.TSpin({page:this.page});
	
	this.baseCreate();
	
	this.isFirst = true;
	
};

Yacon.component.TSqlGrid.prototype = {
		
	baseCreate: function(){
		
		this.dataSet = new Yacon.data.DataSet(this.page);
		this.dataSet.component = this;
		this.dataSet.elementID = this.elementID;
		this.dataSet.setBody("absolutePage","1");
		this.dataSet.defaultMethod = this.view.grid.excute;
		this.dataSet.refreshMethod = this.view.grid.refresh;
		
		//字段处理
		this.fields = {};
		var tmpFields = this.view.grid.fields;
		for(var i=0;i<tmpFields.length;i++){
			var tmpField = tmpFields[i];
			this.fields[tmpField.name] = tmpField;		
		};
		
	},	
	
	/* 获取HTML信息 */	
	getHtml: function(){
		
		var html = "";
		
		html += "<div class='panel row-ht-auto col' role='sqlgrid' ";
		
		html += " lily-id='"+this.elementID+"' lily-type='"+this.elementType+"' ";
		
		if(!Yacon.isEmpty(this.element.grid.master)){
			html += " lily-master='"+this.element.grid.master.id+"' ";
		}
		
		html += ">";
		
		/* 标题 */
		this.title = new Yacon.component.TSqlGridTitle(this.view.grid.title);
		this.title.parent = this;
		html += this.title.getHtml();
		
		/* 底部信息 */
		if(this.view.grid.bottom){
			this.foot = new Yacon.component.TSqlGridFoot(this.view.grid.bottom);
			this.foot.parent = this;
			this.foot.pageSize = this.view.grid.pageSize;
		}
				
		/* 体信息 */
		this.body = new Yacon.component.TSqlGridBody(this.view);
		this.body.parent = this;
		html += this.body.getHtml();
			
		
		/* 菜单信息 */
		if(this.view.grid.menu){
			this.menu = new Yacon.widget.TMenu(this.view.grid.menu);
			this.menu.parent = this;
			this.menu.dataSet = this.dataSet;
			this.menu.viewSet = this.viewSet;
			this.menu.page = this.page;
			
			html += this.menu.getHtml();
			
		}
		
		html += "</div>";
		
		return html;
		
	},
	
	/* 点击事件 */
	addEvents: function(){
		
		Yacon.callBack(this.elementID+"_beforeEvent", [this,this.page]);
		
		/* 行点击事件 */
		this.addRowClick();
		
		/* 选中首行 */
		this.clickFirst();
		
		/* 菜单点击 */
		if(!Yacon.isEmpty(this.menu)){		
			this.menu.addTopClick(".panel-heading");
			this.menu.addRightClick();
			this.menu.addBottomClick(".panel-heading");		
		}
		
		/* 底层点击方法 */
		if(this.foot){
			this.foot.addEvent();
		}
		
		/* 右键菜单点击 */
		if(!Yacon.isEmpty(this.menu) && !Yacon.isEmpty(this.view.grid.menu) && (this.view.grid.menu.type == "right")){
			
			if(this.isFirst){
				
				var self = this;
				
				Yacon.callBackRight(self.elementID+"-menu", self);
				
				self.isFirst = false;
				
			}

		}
				
		Yacon.callBack(this.elementID+"_afterEvent", [this,this.page]);
		
	},
	
	/* 行点击事件 */
	addRowClick: function(){
		
		var self = this;
		
		var search = this.page.element.search +" div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		self.singleTime = null;
		
		$(search + " .panel-body tbody tr").click(function(e){
			
			if(!Yacon.isEmpty(self.singleTime)){
				clearTimeout(self.singleTime);
			}
			
			var childSelf = this;
			
			self.singleTime = setTimeout(function(){
						
				$(search + " .panel-body tbody tr").removeClass("active");
				$(childSelf).addClass("active");
				
				var flag = true;
				
				/* 行点击前 */
				if (Yacon.isfireuserEvent(self.elementID+"_onRowClickBefore")){
					flag = Yacon.fireUserEvent(self.elementID+"_onRowClickBefore",[self,self.page]);
				}
					
				if(flag){
					
					self.clickRow();
					
					var foreignGrids = $("div[lily-master='"+self.elementID+"']");
					if(foreignGrids.length>0){
						
						for(var i=0;i<foreignGrids.length;i++){
							var id = foreignGrids.eq(i).attr("lily-id");
							var detailGrid = self.page.find(id);
							detailGrid.getDataSet();
							detailGrid.dataSet.refresh();
						}
						
					}
					
				}
					
				/* 行点击后 */
				if (Yacon.isfireuserEvent(self.elementID+"_onRowClickAfter"))
					Yacon.fireUserEvent(self.elementID+"_onRowClickAfter",[self,self.page]);
				
			},300);

					
		});
		
		$(search + " .panel-body tbody tr").dblclick(function(e){
			
			if(!Yacon.isEmpty(self.singleTime)){
				clearTimeout(self.singleTime);
			}
				
			$(search + " .panel-body tbody tr").removeClass("active");
			$(this).addClass("active");
			
			var flag = true;
			
			/* 行双击前 */
			if (Yacon.isfireuserEvent(self.elementID+"_onRowDbClickBefore")){
				flag = Yacon.fireUserEvent(self.elementID+"_onRowDbClickBefore",[self,self.page]);
			}
							
			self.clickRow();
			
			var foreignGrids = $("div[lily-master='"+self.elementID+"']");
			if(foreignGrids.length>0){
				
				for(var i=0;i<foreignGrids.length;i++){
					var id = foreignGrids.eq(i).attr("lily-id");
					var detailGrid = self.page.find(id);
					detailGrid.getDataSet();
					detailGrid.dataSet.refresh();
				}
				
			}
	
			var detail = self.view.detail;
			
			if(flag){
				
				/* 弹窗处理 */
				if(!Yacon.isEmpty(self.view.detail) && !Yacon.isEmpty(self.view.detail.path)){
					
					var width = detail.width;
					var height = detail.height;
					var path =  detail.path;
					
					self.dataSet.setAction("type","0");
					
					if(!Yacon.isEmpty(detail.param)){
						var params = detail.param;
						for(var i=0;i<params.length;i++){
							
							var paramsKey = params[i].key;
							var foreignKey = params[i].foreign;
							
							if(foreignKey.startsWith("#")){							
								foreignKey = foreignKey.substring(1);					
								path = Yacon.addUrlParam(paramsKey,self.page.element.parameter[foreignKey],path);							
							}else{
								path = Yacon.addUrlParam(paramsKey,self.dataSet.getDataSetValue(foreignKey.toUpperCase()),path);							
							}
							
						}
					}
					
					path = Yacon.addUrlParam("state", "past", path);
					
					var autoClose = detail.autoClose;
					if(autoClose == undefined){
						autoClose = true;
					}
					
					Yacon.showModal({
						heigth : height ,
						width : width ,
						url : path ,
						dataSet : self.dataSet,
						autoClose : autoClose
					});
					
				}
				
			}
	
			/* 行双击后 */
			if (Yacon.isfireuserEvent(self.elementID+"_onRowDbClickAfter"))
				Yacon.fireUserEvent(self.elementID+"_onRowDbClickAfter",[self,self.page]);

		});	
		
		/* 复选框事件 */
		$(search + " input.check-all-field").click(function(e){
			 
			 if($(this).is(':checked')){
				 $(search + " input.check-field").prop("checked",$(this).is(':checked'));
			 }else{
				 $(search + " input.check-field").prop("checked",$(this).is(':checked'));
			 }		 
			 
		});
		
		
	},
	
	/* 选中首行 */
	clickFirst: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		var active = $(search+" .panel-body tbody tr.active");
		
		if(active.length <= 0){
			
			$(search+" .panel-body tbody tr").removeClass("active");
			
			var trs = $(search+" .panel-body tbody tr");
			
			if(trs.length>0){
				trs.eq(0).click();
			}else{
				
				var foreignGrids = $("div[lily-master='"+this.elementID+"']");
				if(foreignGrids.length>0){
					
					for(var i=0;i<foreignGrids.length;i++){
						var id = foreignGrids.eq(i).attr("lily-id");
						var detailGrid = this.page.find(id);
						detailGrid.body.reset();
						if(detailGrid.foot){
							detailGrid.foot.reset();
						}
					}
					
				}
				
			}
		}
		
		this.clickRow();
		
	},
	
	/* 行点击 */
	clickRow: function(){		
		this.dataSet.clearDataSet();	
		this.dataSet.getDataSet();	
	},
	
	instData: function(){
		
		var typ = this.dataSet.getAction("type");		

		if(typ == "1"){
			this.insertDataSet();
		}
		
		else if(typ == "2"){
			this.editDataSet();
		}
		
		else if(typ == "3"){
			
		}
		
		return true;

	},
	
	insertDataSet: function(){
		
		if(Yacon.isEmpty(this.view.detail) || Yacon.isEmpty(this.view.detail.path)){			
			this.clickRow();		
			return;			
		}
			
		var alls;
		
		this.control = "#"+this.elementID+"_window ";
		
		if(this.control){			
			alls = $(this.control+" .lily-field");		
		}else{
			alls = $(".lily-field");
		}

		if(alls){
			
			var size = alls.length;	
			
			//重新定义dataSet
			this.dataSet.dataset = new Yacon.container.Table();
			
			this.dataSet.getFirstRecord();	
			
			for(var i=0;i<size;i++){
			
				var active = alls.eq(i);
				var fieldName = active.attr("field-name");
				var fieldValue = active.val();
				
				//校验字段
				if(!this.checkField(active)){
					Yacon.throwException(); 
				};
				
				if(Yacon.isNull(fieldValue)){
					fieldValue = "";
				}
				
				//复选框
				var fieldTyp = active.attr("field-type");
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "check"){
					var allChecks = active.find("input[type='checkbox']:checked");
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
					
				}
				
				//单选框
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "radio"){
					var allChecks = active.find("input[type='radio']:checked");
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
					
				}
				
				//Label信息
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "label"){
					fieldValue = active.html();
				}
				
				var fieldOldValue = fieldValue;
				
				this.dataSet.setDataSet(fieldName,fieldValue,fieldOldValue);
				
			}
			
		}
		
	},
	
	checkField:function(active){
		
		var fieldLabel = active.attr("field-label");
		var fieldValue = active.val();
		var fieldType = active.attr("field-type");
		var fieldMaxLength = Yacon.getInt(active.attr("field-max-length"));
		
		if(fieldType == "input" || fieldType == "textarea"){
			
			if(fieldMaxLength == 0){
				return true;
			}
			
			if(fieldValue.length > fieldMaxLength){
				alert(fieldLabel+"信息过长！");
				return false;
			}
			
		}
		
		return true;
	},
	
	editDataSet: function(){
		
		if(Yacon.isEmpty(this.view.detail) || Yacon.isEmpty(this.view.detail.path)){		
			this.clickRow();		
			return;		
		}
		
		var alls;
		
		if(this.control){			
			alls = $(this.control+" .lily-field");		
		}else{
			alls = $(".lily-field");
		}
		
		if(alls){
			
			var size = alls.length;	
			
			/*this.dataSet.dataset = new Yacon.container.Table();*/
			
			this.dataSet.getFirstRecord();	
			
			for(var i=0;i<size;i++){
			
				var active = alls.eq(i);
				var fieldName = active.attr("field-name");
				var fieldValue = active.val();
				
				if(Yacon.isNull(fieldValue)){
					fieldValue = "";
				}
				
				//校验字段
				if(!this.checkField(active)){
					Yacon.throwException(); 
				};
				
				//复选框
				var fieldTyp = active.attr("field-type");
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "check"){
					
					fieldValue = "";
					
					var allChecks = active.find("input[type='checkbox']:checked");
					
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
				}
				
				//单选框
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "radio"){
					
					fieldValue = "";
					
					var allChecks = active.find("input[type='radio']:checked");
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
					
				}
				
				//Label信息
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "label"){
					fieldValue = active.html();
				}
				
				var activeRecord = this.dataSet.getFieldValue(fieldName);
				
				if(Yacon.isEmpty(activeRecord)){
					this.dataSet.setDataSet(fieldName,"");
				}
				
				this.dataSet.getFieldValue(fieldName).setFieldValue("fieldvalue",fieldValue);
						
			}
			
		}
	},
	
	showData: function(){
		
		var record = this.dataSet.getFirstRecord();
		var fieldSize = record.getFieldCount();
		
		for(var i=0;i<fieldSize;i++){
			
			var field = record.getField(i);			
			var fieldName = field.getFieldName();			
			var fieldValue = field.getFieldValue().getFieldValue("fieldoldvalue");	
			
			this.control = "#"+this.elementID +"_window";
			
			var formField = $(this.control+" .lily-field[field-name='"+fieldName+"']");
			var fieldTyp = formField.attr("field-type");
			
			/* 复选框 */
			if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "check"){
				var item = fieldValue.split(",");
				for(var j=0;j<item.length;j++){					
					var itemVal = item[j];				
					formField.find("input[field-key='"+itemVal+"']")
					         .prop("checked","true");				
				}			
			}
			
			/* 单选框 */
			if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "radio"){			
				formField.find("input[field-key='"+fieldValue+"']")
				         .prop("checked","true");							
			}
			
			//Label信息
			if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "label"){			
				formField.html(fieldValue);
			}
			
			else{
				$(this.control+" .lily-field[field-name='"+fieldName+"']").val(fieldValue);
				$(this.control+" .lily-fix-field[field-fix-name='"+fieldName+"']").val(fieldValue);
			}
			
		}
	},
	
	/* 创建新行 */
	createRow: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		var html = "";
		
		if($("body").hasClass("mid")){
			html = "<tr class='active active-row add-row' style='height:31px;'>";
		}else{
			html = "<tr class='active active-row add-row' style='height:23px;'>";
		}
		
		var idx = 0;
			
		var head = $(search+" thead tr th");
		var grid = $(search);
		
		if(this.view.grid.choice=="check"){
			
			if($("body").hasClass("mid")){
	            html += "<td style='width:25px;'>";        
	            html += "<label class='checkbox-inline'>";
	            html += "<input type='checkbox' style='position:static;' class='check-field' id='inlineCheckbox1' value='option1'>&nbsp;</input>";
			}else{
				html += "<td style='width:20px;'>";		
				html += "<label class='checkbox-inline' style='padding-left: 21px;'>";
				html += "<input type='checkbox' style='position:static;width:10px;' class='check-field' id='inlineCheckbox1' value='option1'>&nbsp;</input>";
			}
		
			html += "</label>";		
			html += "</td>";
			idx++;
		}
		
		for(;idx<=head.length-1;idx++){
			
			var activeHead = head.eq(idx);
			
			var fieldName = activeHead.attr("field_name");	
			var fieldTyp = activeHead.attr("field_typ");
			var fieldExp = activeHead.attr("field_exp");
			/* 9px 内外补 */			
			var width = activeHead.css("width");
			var display = activeHead.css("display");
					
			if(display == "none"){			
				html += "<td style='width:"+width+";display:none;' field_name='"+fieldName+"' field_text='' field_val='' ";	
				
				html += " field_typ='"+fieldTyp+"' ";
				html += " field_exp='"+fieldExp+"' ";
				html += " field_old_val='' ";
				
				html += "></td>";
				
			}else{
				width = (Yacon.getPx(width)-9) + "px";
				
				html += "<td ";
				
				html += " style='width:"+width+"' "
				
				html += " field_name='"+fieldName+"' field_text='' field_val='' ";
				
				html += " field_typ='"+fieldTyp+"' ";
				html += " field_exp='"+fieldExp+"' ";
				html += " field_old_val='' ";
				
				html += ">"
					
				html += "</td>";	
				
			}

			
		}
		
		html += "</tr>";
		
		var active = $(search+" tbody tr.active");
		
		if(active.length > 0){
			active.removeClass("active");
			active.after(html);
		}else{
			$(search +" tbody").append(html);
		}
		
		
	},
	
	createRowEvent: function(dataSet){
		
		var self = this;
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		$(search + " .panel-body tbody tr").unbind("click");
		
		$(search + " tbody tr.active td").click(function(){
			
			var fieldName = $(this).attr("field_name");
			
			if(Yacon.isTrue(self.fields[fieldName].isInsert)){
				
				var info = $(this).text();
				
				$(this).empty();
			
				var fieldTyp = $(this).attr("field_typ");
				var fieldExp = $(this).attr("field_exp");
				var width = (Yacon.getPx($(this).css("width")) - 9) + "px";
				
				var html = "";
				
				if(fieldTyp == "TEXT"){
					
					html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='text' value='"+info+"'/>";
					
				}
				
				else if(fieldTyp == "NUMBER"){
					html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='number' value='"+info+"'/>";
				}
				
				else if(fieldTyp == "INT"){
					html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='number' value='"+info+"'/>";
				}
				
				else if(fieldTyp == "DROP_SELECT"){
					
					html += "<select style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' value=''>";
					
					html += "<option value=''></option>";
					
					if(!Yacon.isEmpty(fieldExp)){
						var activeEnum = self.view.grid.enums[fieldExp];		
						if(!Yacon.isEmpty(activeEnum)){
							
							for(var i=0;i<activeEnum.length;i++){
								
								html += "<option value='"+activeEnum[i].key+"'>"+activeEnum[i].value+"</option>";
								
							}
							
						}	
					}
					
					html += "</select>";
					
					/* 下拉失去点击事件 */
					$(this).unbind("click");

				}
				
				$(this).append(html);
				
				$(this).find("input").focus();		
				$(this).find("input").unbind("blur");			
				$(this).find("input").blur(function(){
					
					var value = $(this).val();
					
					value = Yacon.stripDefend(value);
					
					var parent = $(this).parent();
					
					parent.empty();
					parent.append(value);
					
					parent.attr("field_text",value);
					parent.attr("field_val",value);
					
				});
				
				/*$(this).find("select").focus();*/
				$(this).find("select").unbind("change");	
				$(this).find("select").change(function(){
					
					var value = $(this).val();
					var parent = $(this).parent();
					
					value = Yacon.stripDefend(value);
					
					parent.attr("field_text",value);
					parent.attr("field_val",value);
					
				});
				
			}

		});
		
	},
	
	/* 修改行 */
	editRow: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		var active = $(search+" tbody tr.active");			
		active.addClass("active-row");
		active.addClass("edit-row");
		
		/* 原始值赋值 */
		var TDs = active.find("td");
		var TDSize = TDs.length;
		for(var i=0;i<TDSize;i++){
			var activeTD = TDs.eq(i);
			var value = activeTD.attr("field_val");
			if(value != undefined){
				activeTD.attr("field_old_val",value);
			}	
		}
		
	},
	
	editRowEvent: function(dataSet){
		
		var self = this;
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		$(search + " .panel-body tbody tr").unbind("click");
		
		$(search + " tbody tr.active td").click(function(){
			
			var fieldName = $(this).attr("field_name");
			
			if(Yacon.isTrue(self.fields[fieldName].isEdit)){
				
				var info = $(this).text();
				
				$(this).empty();
				
				
				var fieldTyp = $(this).attr("field_typ");
				var fieldExp = $(this).attr("field_exp");
				var width = (Yacon.getPx($(this).css("width")) - 9) + "px";
				
				var html = "";
				
				if(fieldTyp == "TEXT"){
					
					html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='text' value='"+info+"'/>";
					
				}
				
				else if(fieldTyp == "INT"){
					html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='number' value='"+info+"'/>";
				}
				
				else if(fieldTyp == "NUMBER"){
					html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='number' value='"+info+"'/>";
				}
				
				else if(fieldTyp == "DROP_SELECT"){
					
					html += "<select style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' value=''>";
					
					html += "<option value=''></option>";
					
					if(!Yacon.isEmpty(fieldExp)){
						var activeEnum = self.view.grid.enums[fieldExp];		
						if(!Yacon.isEmpty(activeEnum)){
							
							for(var i=0;i<activeEnum.length;i++){
								
								html += "<option value='"+activeEnum[i].key+"'>"+activeEnum[i].value+"</option>";
								
							}
							
						}	
					}
					
					html += "</select>";
					
					/* 下拉失去点击事件 */
					$(this).unbind("click");

				}
				
				$(this).append(html);
				
				$(this).find("input").focus();		
				$(this).find("input").unbind("blur");			
				$(this).find("input").blur(function(){
					
					var value = $(this).val();
					var parent = $(this).parent();
					
					parent.empty();
					parent.append(value);
					
					parent.attr("field_text",value);
					parent.attr("field_val",value);
					
				});
				
				/*$(this).find("select").focus();*/
				$(this).find("select").unbind("change");	
				$(this).find("select").change(function(){
					
					var value = $(this).val();
					var parent = $(this).parent();
					
					parent.attr("field_text",value);
					parent.attr("field_val",value);
					
				});
				
			};
			
		});
		
	},
	
	refreshElement: function(){
		
		var html = "";
		
		this.view = this.dataSet.getDataValue();	
		
		this.body.refresh();
			
		if(this.foot){
			this.foot.refresh();
		}	
		
		this.addEvents();
		
	},
	
	refresh: function(){
		this.dataSet.refresh();		
	},
	
	getDataSet: function(){
		this.dataSet.getDataSet("flat");
		this.dataSet.next();
		return this;
	},
	
	getCheckDataSet: function(){
		this.dataSet.getDataSet("check");
		this.dataSet.dataset.beforeFirst();
		return this;
	},
	
	getFieldValue: function(fieldName){
		return this.dataSet.getDataSetValue(fieldName);
	},
	
	setFieldValue:function(fieldName,fieldValue){
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		var searchBody = search +" .panel-body .table-body tbody";
		var searchBodyActive = searchBody + " tr.active td[field_name='"+fieldName.toUpperCase().trim()+"']";
		
		if(!Yacon.isEmpty(searchBodyActive)){
			$(searchBodyActive).attr("field_text",fieldValue);
			$(searchBodyActive).attr("field_val",fieldValue);
			$(searchBodyActive).text(fieldValue);
		}
	},
	
	next: function(){
		return this.dataSet.next();
	},
	
	getRecordCount: function(){
		return this.dataSet.getDataSetCount();
	},
	
	/* 后续布局处理 */
	layoutBefore:function(){
		
		this.body.refresh();
		
		this.spinIn();
		
		this.spinHidden();
		
	},
	
	spinIn: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";

		this.spinner.createSpinner(search);
		
		this.spinner.spinIn(search);
		
	},
	
	spinOut: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		if(!Yacon.isEmpty(this.spinner)){
			this.spinner.spinOut(search);
		}	
		
	},
	
	spinShow: function(){
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";

		if(!Yacon.isEmpty(this.spinner)){
			this.spinner.spinShow(search);
		}
		
	},
	
	spinHidden: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";

		if(!Yacon.isEmpty(this.spinner)){
			this.spinner.spinHidden(search);
		}
		
	},
	
	getJQueryTable: function(){		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";		
		return $(search);		
	},
	
	getJQueryHead:function(){		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";	
		return $(search+" .panel-body .table-title thead");		
	},
	
	getJQueryBody:function(){
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		return $(search+" .panel-body .table-body tbody");
	},
	
	getJQueryHeadTD:function(fieldName){
		
		if(Yacon.isEmpty(fieldName)){
			return this.getJQueryHead().find("th");
		}else{
			return this.getJQueryHead().find("th[field_name='"+fieldName.toUpperCase().trim()+"']");
		}
		
	},
	
	getJQueryBodyTD:function(fieldName){
		
		if(Yacon.isEmpty(fieldName)){
			return this.getJQueryBody().find("td");
		}else{
			return this.getJQueryBody().find("td[field_name='"+fieldName.toUpperCase().trim()+"']");
		}
		
	},
	
	/* 修改表格单元格样式 */
	changeStyle: function(tdObj){
		
		var self = this;
		
		var info = tdObj.text();
		
		tdObj.empty();
			
		var fieldTyp = tdObj.attr("field_typ");
		var fieldExp = tdObj.attr("field_exp");
		var width = (Yacon.getPx(tdObj.css("width")) - 9) + "px";
		var fieldName = tdObj.attr("field_name");
		
		var html = "";
		
		if(fieldTyp == "TEXT"){
			
			html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='text' value='"+info+"'/>";
			
		}
		
		else if(fieldTyp == "NUMBER"){
			html += "<input style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' type='number' value='"+info+"'/>";
		}
		
		else if(fieldTyp == "DROP_SELECT"){
			
			html += "<select style='width:"+width+";' id='"+fieldName+"' name='"+fieldName+"' value=''>";
			
			html += "<option value=''></option>";
			
			if(!Yacon.isEmpty(fieldExp)){
				var activeEnum = this.view.grid.enums[fieldExp];		
				if(!Yacon.isEmpty(activeEnum)){
					
					for(var i=0;i<activeEnum.length;i++){
						
						html += "<option value='"+activeEnum[i].key+"'>"+activeEnum[i].value+"</option>";
						
					}
					
				}	
			}
			
			html += "</select>";
			
			/* 下拉失去点击事件 */
			tdObj.unbind("click");

		}
		
		tdObj.append(html);
		
		tdObj.find("input").focus();		
		tdObj.find("input").unbind("blur");			
		tdObj.find("input").blur(function(){
			
			var value = $(this).val();
			var parent = $(this).parent();
			
			parent.empty();
			parent.append(value);
			
			parent.attr("field_text",value);
			parent.attr("field_val",value);
			
			Yacon.callBack(self.elementID+"_"+fieldName+"_blur", [self,self.page,$(this)]);
			
		});
		
		/*$(this).find("select").focus();*/
		tdObj.find("select").unbind("change");	
		tdObj.find("select").change(function(){
			
			var value = $(this).val();
			var parent = $(this).parent();
			
			parent.attr("field_text",value);
			parent.attr("field_val",value);
			
			Yacon.callBack(self.elementID+"_"+fieldName+"_change", [self,self.page,$(this)]);
			
		});
		
		tdObj.find("select").unbind("blur");	
		tdObj.find("select").blur(function(){

			Yacon.callBack(self.elementID+"_"+fieldName+"_blur", [self,self.page,$(this)]);
		});
		
	},
	
	/* 获取主表   */
	getMaster: function(){
		var masterID = "";
		if(this.element.grid.master){			
			masterID = this.element.grid.master.id;			
			return this.page.find(masterID);			
		}else{
			return;
		}
	}
		
};